﻿using System;
using UnityEngine;

[ExecuteInEditMode]
public abstract class USEventBase : MonoBehaviour
{
    [SerializeField]
    private float duration = -1f;
    [SerializeField]
    private float firetime = -1f;

    protected USEventBase()
    {
    }

    public virtual void EndEvent()
    {
    }

    public abstract void FireEvent();
    public virtual void ManuallySetTime(float deltaTime)
    {
    }

    public virtual void PauseEvent()
    {
    }

    public abstract void ProcessEvent(float runningTime);
    public virtual void ResumeEvent()
    {
    }

    public virtual void StopEvent()
    {
    }

    public virtual void UndoEvent()
    {
    }

    public GameObject AffectedObject
    {
        get
        {
            return this.TimelineContainer.AffectedObject.gameObject;
        }
    }

    public float Duration
    {
        get
        {
            return this.duration;
        }
        set
        {
            this.duration = value;
        }
    }

    public float Firetime
    {
        get
        {
            return this.firetime;
        }
        set
        {
            this.firetime = value;
            if (this.firetime < 0f)
            {
                this.firetime = 0f;
            }
            if (this.firetime > this.Sequence.Duration)
            {
                this.firetime = this.Sequence.Duration;
            }
        }
    }

    public bool IsFireAndForgetEvent
    {
        get
        {
            return (this.Duration < 0f);
        }
    }

    public USSequencer Sequence
    {
        get
        {
            return ((this.Timeline == null) ? null : this.Timeline.Sequence);
        }
    }

    public USTimelineBase Timeline
    {
        get
        {
            if (base.transform.parent == null)
            {
                return null;
            }
            USTimelineBase component = base.transform.parent.GetComponent<USTimelineBase>();
            if (component == null)
            {
                Debug.LogWarning(base.name + "有问题：父节点没有添加USTimeLineBase组件. " + base.name + "的父节点是 : " + base.transform.parent.name);
            }
            return component;
        }
    }

    public USTimelineContainer TimelineContainer
    {
        get
        {
            return this.Timeline.TimelineContainer;
        }
    }
}

